<?php

namespace addons\mall\library;

use app\common\library\Auth;
use app\common\library\Email;
use app\common\model\User;
use think\Config;
use think\Exception;
use think\Queue;
use think\View;

class Service
{

    public static function smsSend($mobile,$code = null,$event = 'default'){
        $config = get_addon_config('mall');
        if ($event && !in_array($event, explode(',', $config['emailnotice']))) {
            return false;
        }
        $data = [
            'method' => 'send',
            'mobile' => $mobile,
            'code' => $code,
            'event' => $event,
        ];
        return self::push('addons\mall\controller\queue\SmsJob', $data);
    }

    /*
     * 给管理员发送短信
     */
    public static function smsAdminNotice($msg = '',$event = null,$template = null){
        $config = get_addon_config('mall');
        if ($config['recivemobile'] && count($config['recivemobile'])>=11) {
            $mobiles = explode(',', $config['recivemobile']);
            foreach($mobiles as $m){
                if(count($m)==11 && is_numeric($m))
                    self::smsNotice($m,$msg,'ordercomplain');
            }
        }
    }

    /*
     * 发送短信通知
     */
    public static function smsNotice($mobile,$msg = '',$event = null,$template = null){
        $config = get_addon_config('mall');
        if ($event && !in_array($event, explode(',', $config['emailnotice']))) {
            return false;
        }
        $data = [
            'method' => 'notice',
            'mobile' => $mobile,
            'msg' => $msg,
            'template' => $template,
        ];
        return self::push('addons\mall\controller\queue\SmsJob', $data);
    }

    public static function push($job, $data = '', $queue = null){
        return Queue::push($job, $data, $queue);
    }

    public static function later($delay, $job, $data = '', $queue = null){
        return Queue::later($delay,$job, $data, $queue);
    }
}